package com.bosicen.crm.dao.sysmanage;

import java.util.List;


import org.springframework.stereotype.Component;
import com.bosicen.crm.dao.HibernateDao;
import com.bosicen.crm.dao.entity.ProductType;
import com.bosicen.crm.tools.Page;

/**
 * 商品类型
 * @author tigerlei
 *
 */
@Component("productTypeDao")
@SuppressWarnings("unchecked")
public class ProductTypeDao extends HibernateDao<ProductType, Integer> {

	/****
	 * 查询列表
	 * @param id
	 * @return
	 */
	
	public List<ProductType> findProductTypeList(ProductType producttype){
		String sql = "from ProductType where companyid=? ";
		if(producttype.getFlag()>0){
			sql += " and flag="+producttype.getFlag();
		}
		sql += "  order by id asc ";
		return this.getSession().createQuery(sql).setParameter(0, producttype.getCompanyid()).list();
	}
	
	/**
	 * 按ID查询
	 * @param id
	 * @return
	 */
	public ProductType findProductTypeById(int id){
		//return (ProductType) this.getSession().get(ProductType.class, id);
		return this.get(id);
	}
	
	/***
	 * 删除
	 * @param c
	 */
	public void delProductType(ProductType c){
		this.getSession().createQuery("delete ProductType where id=?").setParameter(0, c.getId()).executeUpdate();
		//this.delete(c.getId());
	}
	
	/**
	 * 保存
	 */
	public void saveOrUpdate(ProductType productType){
//		this.getSession().saveOrUpdate(productType);
		this.getSession().merge(productType);
	}
	
	/****
	 * 查询列表
	 * @param id
	 * @return
	 */
	
	public Page findProductType4Page(int companyid,Page page){
		return this.findPage(page, " from ProductType where companyid=?  order by id desc", companyid);
	}
	
}
